<?php

namespace app\admin\controller;

use app\admin\service\UserService;

/**
 * 登录类
 * Class Login
 * @package app\controller
 */
class Login
{
    /**
     * 登录
     * @return string
     */
    public function index()
    {
        $username = request()->post('username', '', 'trim');
        $password = request()->post('password', '', 'trim');
        $ip = request()->ip();
        if (empty($username)) {
            return json_error(12007);
        }
        if (empty($password)) {
            return json_error(12008);
        }
        // 登录验证并返回token;
        $result = UserService::login($username, $password, $ip);
        return json_ok($result, 11108);
    }
}